# -*- coding: UTF-8 -*-
import MySQLdb
import MySQLdb.cursors
from scrapy.utils.project import get_project_settings


class LogCommon(object):

	@staticmethod
	# 插入数据表
	def insert_log(sql):
		settings = get_project_settings()
		db_conf = settings.get('DB_CONF')
		try:
			conn = MySQLdb.connect(host=db_conf['host'],
								   user=db_conf['user'],
								   passwd=db_conf['passwd'],
								   db=db_conf['db'],
								   port=db_conf['port'],
								   charset=db_conf['charset'])
			cur = conn.cursor()
			cur.execute(sql)
			conn.commit()
		except:
			raise
		finally:
			cur.close()
			conn.close()

